package com.java.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.java.service.RacePostService;
import com.java.util.resp.BaseRespone;
import com.java.util.resp.TableRespone;
import com.java.util.servlet.ServletUtil;

@RestController
//@RequestMapping("/post")
public class RacePostController {

	@Autowired
	RacePostService postService;

	@PostMapping("/createPost")
	public BaseRespone createPost(@RequestParam(required = false) String userId,
			@RequestParam(required = false) String postText) {
		return postService.createPost(ServletUtil.getUserId(userId), postText);
	}

	@PostMapping("/upodatePost")
	public BaseRespone upodatePost(@RequestParam(required = false) String postId,
			@RequestParam(required = false) String postText) {
		return postService.upodatePost(postId, postText);
	}

	@PostMapping("/delPost")
	public BaseRespone delPost(@RequestParam(required = false) String postId) {
		return postService.delPost(postId);
	}

	@PostMapping("/getPosts")
	public TableRespone getPosts(@RequestParam(required = false) String userId,
			@RequestParam(required = false, defaultValue = "0") int page,
			@RequestParam(required = false, defaultValue = "0") int size) {
		return postService.getPosts(ServletUtil.getUserId(userId), page, size);
	}

	@PostMapping("/addComment")
	public BaseRespone addComment(
			@RequestParam(required = false) String commentUserId,
			@RequestParam(required = false) String commentPostId, 
			@RequestParam(required = false) String commentParentId,
			@RequestParam(required = false) String commentText) {
		return postService.addComment(ServletUtil.getUserId(commentUserId), commentPostId, commentParentId, commentText);
	}

	@PostMapping("/delComment")
	public BaseRespone delComment(@RequestParam(required = false) String commentId) {
		return postService.delComment(commentId);
	}

	@PostMapping("/getComments")
	public TableRespone getComments(@RequestParam(required = false) String userId,
			@RequestParam(required = false) String postId, 
			@RequestParam(required = false, defaultValue = "0") int page,
			@RequestParam(required = false, defaultValue = "0") int size) {
		return postService.getComments(ServletUtil.getUserId(userId), postId, page, size);
	}
}
